import java.util.ArrayList;


public class M {
	
	private ArrayList<V> matrice;
	
	/*constructeurs*/
	
	public M()
	{
		this.matrice = new ArrayList<V>();
	}
	
	public M(String s,D d)
	{
		
	}
	
	public M(Integer i)
	{
		this.matrice = new ArrayList<V>();
		this.matrice.add(new V(i));
	}
	
	public M(M matrice)
	{
		this();
		for(int i = 0; i < matrice.size();i++)
			this.matrice.add(new V(matrice.getvecC(i)));
	}
	
	/*accesseurs*/
	
	public V getvecC(int i)
	{
		return this.matrice.get(i);
	}
	
	public V getvecL(int i)
	{
		V tmp = new V();
		for(int j = 0; j < this.size();j++)
			tmp.ajout_integer(this.get(i,j));
		return tmp;
	}
	
	public Integer get(int l , int c)
	{
		if(c < this.matrice.size())
			if(this.matrice.size()>0)
				if(l < this.matrice.get(0).size())
					return this.matrice.get(c).get(l);
		return null;
	}
	
	public void setvecC(int i, V c)
	{
		this.matrice.set(i,c);
	}
	
	public void setvecL(int i ,V l)
	{
		for(int j = 0; j < this.size();j++)
			this.matrice.get(j).set(i,l.get(i));
	}
	
	public void set(int l,int c, Integer val)
	{
		this.matrice.get(c).set(l,val);
	}
	
	public void suprC(int c)
	{
		if ( (c < this.size())&&(c >=0) )
			this.matrice.remove(c);
			this.size();
	}
	
	public void suprL(int l)
	{
		for(int i = 0; i < this.size();i++)
			this.matrice.get(i).supr(l);
	}
	
	public int size()
	{
		return this.matrice.size();
	}
	
	public int sizeC() 
	{
		if(this.matrice.size()>0)
			return this.matrice.get(0).size();
		return 0;
	}
	
	/* fonctions */
	
	public void add_Vect_C(V c)
	{
		this.matrice.add(c);
	}
	
	public void add_Vect_L(V l)
	{
		if(this.matrice.size() == 0)
			for(int i = 0;i <l.getVecteur().size();i++)
				this.matrice.add(new V());
		
		for(int i = 0; i < this.matrice.size();i++)
		{
			this.matrice.get(i).ajout_integer(l.getVecteur().get(i));
		}
	}
	
	public void add_Mat_C(M m)
	{
		for(int i = 0;i < m.size();i++)
			this.add_Vect_C(m.getvecC(i));
	}
	
	public void add_Mat_L(M m)
	{
		for(int i = 0; i < m.sizeC();i++)
			this.add_Vect_L(m.getvecL(i));
	}
	
	public void clear()
	{
		for(int i = 0; i < this.size();i++)
			this.matrice.get(i).clear();
		this.matrice.clear();
	}

	/*fonction d'affichage */

	public void listerMatrice()
	{
		System.out.println("_______________________");
		System.out.println("Matrice ::");
		for(int j = 0; j < this.sizeC();j++)
		{
			for(int i = 0; i < this.size();i++)
				System.out.print(D.getInstance().decode(this.get(j,i)) + " ");
			System.out.println();
		}
		System.out.println("_______________________");
	}

	public String toString() {
		String tmp = null;
		tmp = "_______________________\n";
		tmp += "Matrice ::\n";
		if(this.size() > 0)
			for(int j = 0; j < this.matrice.get(0).size();j++)

			{
				for(int i = 0; i < this.size();i++)
					tmp += this.get(j,i)+" ";
				tmp +="\n";
			}
		tmp += "\n_______________________\n";
		return tmp;
	}
	
	
	/* Test Unitaire */
	
	@SuppressWarnings("unused")
	public static void main(String Args[]){

		V v1 = new V();
		for(int i = 0;i<10;i++)
			v1.ajout_integer(i);
		
		M m1 = new M();
		M m2 = new M(1);
		
		System.out.println(v1.toString());
		
		for(int i = 0;i<10;i++)
			m1.add_Vect_L(v1);
		
		V v2 = m1.getvecL(0);
		System.out.println(v2.toString());
		V v3 = m1.getvecC(0);
		System.out.println(v3.toString());
	
		System.out.println(m1.toString());
		
		M m3 = new M(m1);
		System.out.println(m3.toString());
		
	}

}
